// license-header java merge-point
/**
 * This is only generated once! It will never be overwritten.
 * You can (and have to!) safely modify it by hand.
 */
package edu.uwlax.cs.oayonlinestore.entities;

import edu.uwlax.cs.oayonlinestore.vo.CategoryStructureVO;
import edu.uwlax.cs.oayonlinestore.vo.CategoryVO;

public class CategoryDaoImpl extends CategoryDaoBase {
	/**
	 * Retrieves the entity object that is associated with the specified value
	 * object from the object store. If no such entity object exists in the
	 * object store, a new, blank entity is created
	 */
	private Category loadCategoryFromCategoryVO(CategoryVO categoryVO) {

		// A typical implementation looks like this:
		edu.uwlax.cs.oayonlinestore.entities.Category category = this
				.load(categoryVO.getId());
		if (category == null) {
			category = edu.uwlax.cs.oayonlinestore.entities.Category.Factory
					.newInstance();
		}
		return category;

	}

	public Category categoryVOToEntity(CategoryVO categoryVO) {
		Category entity = this.loadCategoryFromCategoryVO(categoryVO);
		this.categoryVOToEntity(categoryVO, entity, true);
		return entity;
	}

	public void toCategoryStructureVO(Category source,
			CategoryStructureVO target) {
		super.toCategoryStructureVO(source, target);
		target.setSubcategories(getSubcategoryDao().findActiveByCategory(
				SubcategoryDao.TRANSFORM_SUBCATEGORYVO, source, true));
	}

	public Category categoryStructureVOToEntity(
			CategoryStructureVO categoryStructureVO) {
		Category entity = this.loadCategoryFromCategoryVO(categoryStructureVO);
		this.categoryStructureVOToEntity(categoryStructureVO, entity, true);
		return entity;
	}

}